<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="上传发票" prop="upInvoice">
        <el-input
          v-model="queryParams.upInvoice"
          placeholder="请输入上传发票"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票含税金额" prop="invoiceTaxAmount">
        <el-input
          v-model="queryParams.invoiceTaxAmount"
          placeholder="请输入发票含税金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票不含税金额" prop="invoiceNotaxAmount">
        <el-input
          v-model="queryParams.invoiceNotaxAmount"
          placeholder="请输入发票不含税金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票税额" prop="invoiceTax">
        <el-input
          v-model="queryParams.invoiceTax"
          placeholder="请输入发票税额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账套配置" prop="accountSetConfiguration">
        <el-input
          v-model="queryParams.accountSetConfiguration"
          placeholder="请输入账套配置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同未收票金额" prop="contractNotaxAmount">
        <el-input
          v-model="queryParams.contractNotaxAmount"
          placeholder="请输入合同未收票金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行方编码" prop="executeCode">
        <el-input
          v-model="queryParams.executeCode"
          placeholder="请输入执行方编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行方名称" prop="executeName">
        <el-input
          v-model="queryParams.executeName"
          placeholder="请输入执行方名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款单位" prop="receiveUnit">
        <el-input
          v-model="queryParams.receiveUnit"
          placeholder="请输入收款单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款银行" prop="receiveBank">
        <el-input
          v-model="queryParams.receiveBank"
          placeholder="请输入收款银行"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行方接收邮箱" prop="executeEmail">
        <el-input
          v-model="queryParams.executeEmail"
          placeholder="请输入执行方接收邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行方联系方式" prop="executePhone">
        <el-input
          v-model="queryParams.executePhone"
          placeholder="请输入执行方联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="付款申请金额" prop="payAmount">
        <el-input
          v-model="queryParams.payAmount"
          placeholder="请输入付款申请金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票张数" prop="payInvoiceNum">
        <el-input
          v-model="queryParams.payInvoiceNum"
          placeholder="请输入发票张数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="付款申请金额大写" prop="payAmountDa">
        <el-input
          v-model="queryParams.payAmountDa"
          placeholder="请输入付款申请金额大写"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="借方金额" prop="lendAmount">
        <el-input
          v-model="queryParams.lendAmount"
          placeholder="请输入借方金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票余额" prop="lendInvoiceNum">
        <el-input
          v-model="queryParams.lendInvoiceNum"
          placeholder="请输入发票余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="note">
        <el-input
          v-model="queryParams.note"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确认付款日期" prop="payDate">
        <el-date-picker clearable
          v-model="queryParams.payDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择确认付款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="银行摘要" prop="bankNote">
        <el-input
          v-model="queryParams.bankNote"
          placeholder="请输入银行摘要"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行回单" prop="bankBack">
        <el-input
          v-model="queryParams.bankBack"
          placeholder="请输入银行回单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['agency:projectPay:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['agency:projectPay:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['agency:projectPay:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['agency:projectPay:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectPayList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="上传发票" align="center" prop="upInvoice" />
      <el-table-column label="发票含税金额" align="center" prop="invoiceTaxAmount" />
      <el-table-column label="发票不含税金额" align="center" prop="invoiceNotaxAmount" />
      <el-table-column label="发票税额" align="center" prop="invoiceTax" />
      <el-table-column label="账套配置" align="center" prop="accountSetConfiguration" />
      <el-table-column label="合同未收票金额" align="center" prop="contractNotaxAmount" />
      <el-table-column label="执行方编码" align="center" prop="executeCode" />
      <el-table-column label="执行方名称" align="center" prop="executeName" />
      <el-table-column label="收款单位" align="center" prop="receiveUnit" />
      <el-table-column label="收款银行" align="center" prop="receiveBank" />
      <el-table-column label="执行方接收邮箱" align="center" prop="executeEmail" />
      <el-table-column label="执行方联系方式" align="center" prop="executePhone" />
      <el-table-column label="账号" align="center" prop="account" />
      <el-table-column label="付款申请金额" align="center" prop="payAmount" />
      <el-table-column label="发票张数" align="center" prop="payInvoiceNum" />
      <el-table-column label="付款申请金额大写" align="center" prop="payAmountDa" />
      <el-table-column label="借方金额" align="center" prop="lendAmount" />
      <el-table-column label="发票余额" align="center" prop="lendInvoiceNum" />
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="确认付款日期" align="center" prop="payDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="银行摘要" align="center" prop="bankNote" />
      <el-table-column label="银行回单" align="center" prop="bankBack" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['agency:projectPay:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['agency:projectPay:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目付款对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="上传发票" prop="upInvoice">
          <el-input v-model="form.upInvoice" placeholder="请输入上传发票" />
        </el-form-item>
        <el-form-item label="发票含税金额" prop="invoiceTaxAmount">
          <el-input v-model="form.invoiceTaxAmount" placeholder="请输入发票含税金额" />
        </el-form-item>
        <el-form-item label="发票不含税金额" prop="invoiceNotaxAmount">
          <el-input v-model="form.invoiceNotaxAmount" placeholder="请输入发票不含税金额" />
        </el-form-item>
        <el-form-item label="发票税额" prop="invoiceTax">
          <el-input v-model="form.invoiceTax" placeholder="请输入发票税额" />
        </el-form-item>
        <el-form-item label="账套配置" prop="accountSetConfiguration">
          <el-input v-model="form.accountSetConfiguration" placeholder="请输入账套配置" />
        </el-form-item>
        <el-form-item label="合同未收票金额" prop="contractNotaxAmount">
          <el-input v-model="form.contractNotaxAmount" placeholder="请输入合同未收票金额" />
        </el-form-item>
        <el-form-item label="执行方编码" prop="executeCode">
          <el-input v-model="form.executeCode" placeholder="请输入执行方编码" />
        </el-form-item>
        <el-form-item label="执行方名称" prop="executeName">
          <el-input v-model="form.executeName" placeholder="请输入执行方名称" />
        </el-form-item>
        <el-form-item label="收款单位" prop="receiveUnit">
          <el-input v-model="form.receiveUnit" placeholder="请输入收款单位" />
        </el-form-item>
        <el-form-item label="收款银行" prop="receiveBank">
          <el-input v-model="form.receiveBank" placeholder="请输入收款银行" />
        </el-form-item>
        <el-form-item label="执行方接收邮箱" prop="executeEmail">
          <el-input v-model="form.executeEmail" placeholder="请输入执行方接收邮箱" />
        </el-form-item>
        <el-form-item label="执行方联系方式" prop="executePhone">
          <el-input v-model="form.executePhone" placeholder="请输入执行方联系方式" />
        </el-form-item>
        <el-form-item label="账号" prop="account">
          <el-input v-model="form.account" placeholder="请输入账号" />
        </el-form-item>
        <el-form-item label="付款申请金额" prop="payAmount">
          <el-input v-model="form.payAmount" placeholder="请输入付款申请金额" />
        </el-form-item>
        <el-form-item label="发票张数" prop="payInvoiceNum">
          <el-input v-model="form.payInvoiceNum" placeholder="请输入发票张数" />
        </el-form-item>
        <el-form-item label="付款申请金额大写" prop="payAmountDa">
          <el-input v-model="form.payAmountDa" placeholder="请输入付款申请金额大写" />
        </el-form-item>
        <el-form-item label="借方金额" prop="lendAmount">
          <el-input v-model="form.lendAmount" placeholder="请输入借方金额" />
        </el-form-item>
        <el-form-item label="发票余额" prop="lendInvoiceNum">
          <el-input v-model="form.lendInvoiceNum" placeholder="请输入发票余额" />
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="确认付款日期" prop="payDate">
          <el-date-picker clearable
            v-model="form.payDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择确认付款日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="银行摘要" prop="bankNote">
          <el-input v-model="form.bankNote" placeholder="请输入银行摘要" />
        </el-form-item>
        <el-form-item label="银行回单" prop="bankBack">
          <el-input v-model="form.bankBack" placeholder="请输入银行回单" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProjectPay, getProjectPay, delProjectPay, addProjectPay, updateProjectPay } from "@/api/oa/agency/projectPay";

export default {
  name: "ProjectPay",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目付款表格数据
      projectPayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        upInvoice: null,        invoiceTaxAmount: null,        invoiceNotaxAmount: null,        invoiceTax: null,        accountSetConfiguration: null,        contractNotaxAmount: null,        executeCode: null,        executeName: null,        receiveUnit: null,        receiveBank: null,        executeEmail: null,        executePhone: null,        account: null,        payAmount: null,        payInvoiceNum: null,        payAmountDa: null,        lendAmount: null,        lendInvoiceNum: null,        note: null,        payDate: null,        bankNote: null,        bankBack: null      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目付款列表 */
    getList() {
      this.loading = true;
      listProjectPay(this.queryParams).then(response => {
        this.projectPayList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,        upInvoice: null,        invoiceTaxAmount: null,        invoiceNotaxAmount: null,        invoiceTax: null,        accountSetConfiguration: null,        contractNotaxAmount: null,        executeCode: null,        executeName: null,        receiveUnit: null,        receiveBank: null,        executeEmail: null,        executePhone: null,        account: null,        payAmount: null,        payInvoiceNum: null,        payAmountDa: null,        lendAmount: null,        lendInvoiceNum: null,        note: null,        payDate: null,        bankNote: null,        bankBack: null      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目付款";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProjectPay(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目付款";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProjectPay(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProjectPay(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目付款编号为"' + ids + '"的数据项？').then(function() {
        return delProjectPay(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('agency/projectPay/export', {
        ...this.queryParams
      }, `projectPay_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
